package com.pingancar.creditmanage.service;

import com.pingancar.creditmanage.dao.OrderitemDaoImpl;
import com.pingancar.creditmanage.dao.PAServiceDaoImpl;
import com.pingancar.creditmanage.dao.ServicetypeDaoImpl;
import com.pingancar.creditmanage.dao.ShopInfoDaoImpl;
import com.pingancar.creditmanage.pojo.OrderitemPojo;
import com.pingancar.creditmanage.pojo.PaservicePojo;
import com.pingancar.creditmanage.pojo.ServicetypePojo;
import com.pingancar.creditmanage.pojo.ShopinfoPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by SilverStone-WW on 2015/2/11.
 */
@Service
public class QueryService {
    @Autowired
    PAServiceDaoImpl paServiceDao;
    @Autowired
    OrderitemDaoImpl orderListDao;
    @Autowired
    ShopInfoDaoImpl shopInfoDao;
    @Autowired
    ServicetypeDaoImpl servicetypeDao;

    /**
     * 分页分类按名称加载商家
     * @param type
     * @return
     */
    public List<ShopinfoPojo> getShopinfoList(int type, int offset, int length, String name) {
        return shopInfoDao.getShopList(type, offset, length, name);
    }

    /**
     * 不按服务查询
     * @param offset
     * @param length
     * @param name
     * @return
     */
    public List getAllShopList (int offset, int length, String name) {
        return shopInfoDao.getAllShopList(offset, length, name);
    }

    public Long getCountOfAllShopList (String name) {
        return shopInfoDao.getCountOfAllShopList(name);
    }


    /**
     * 按id查找商家
     * @param id
     * @return
     */
    public ShopinfoPojo getShopinfoById(Integer id) {
        return shopInfoDao.load(id);
    }

    /**
     * 按商家id获取服务列表
     * @param id
     * @return
     */
    public List<PaservicePojo> getServiceListByType(Integer id, Integer type) {
        return paServiceDao.getPaserviceByShop(id, type, 0, -1);
    }

    public List<PaservicePojo> getServiceListByType(Integer id, Integer type, Integer offset, Integer len) {
        return paServiceDao.getPaserviceByShop(id, type, offset, len);
    }

    /**
     * 按服务id获取商家
     * @param id
     * @return
     */
    public ShopinfoPojo getShopinfoByServiceId(Integer id) {
        PaservicePojo paservicePojo = paServiceDao.load(id);
        if (paservicePojo == null)
            return null;

        return paservicePojo.getShopinfo();
    }

    /**
     * 按id加载服务
     * @param id
     * @return
     */
    public PaservicePojo getServiceById (Integer id) {
        return paServiceDao.load(id);
    }

    /**
     * 按订单id查找
     * @param id
     * @return
     */
    public OrderitemPojo getOrderlistById(Integer id) {
        return orderListDao.load(id);
    }

    /**
     * 获取服务类型列表
     * @return
     */
    public List<ServicetypePojo> getServicetype() {
        return servicetypeDao.getAllList();
    }
}
